package com.ruoyi.web.controller.report;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.ReportParam;
import com.ruoyi.report.service.IReportParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报告参数Controller
 * 
 * @author wry
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/report/reportparam")
public class ReportParamController extends BaseController
{
    @Autowired
    private IReportParamService reportParamService;

    /**
     * 查询报告参数列表
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportParam reportParam)
    {
        startPage();
        List<ReportParam> list = reportParamService.selectReportParamList(reportParam);
        return getDataTable(list);
    }

    /**
     * 导出报告参数列表
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:export')")
    @Log(title = "报告参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportParam reportParam)
    {
        List<ReportParam> list = reportParamService.selectReportParamList(reportParam);
        ExcelUtil<ReportParam> util = new ExcelUtil<ReportParam>(ReportParam.class);
        util.exportExcel(response, list, "报告参数数据");
    }

    /**
     * 获取报告参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:query')")
    @GetMapping(value = "/{paramId}")
    public AjaxResult getInfo(@PathVariable("paramId") Long paramId)
    {
        return success(reportParamService.selectReportParamByParamId(paramId));
    }

    /**
     * 新增报告参数
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:add')")
    @Log(title = "报告参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportParam reportParam)
    {
        return toAjax(reportParamService.insertReportParam(reportParam));
    }

    /**
     * 修改报告参数
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:edit')")
    @Log(title = "报告参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportParam reportParam)
    {
        return toAjax(reportParamService.updateReportParam(reportParam));
    }

    /**
     * 删除报告参数
     */
    @PreAuthorize("@ss.hasPermi('report:reportparam:remove')")
    @Log(title = "报告参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paramIds}")
    public AjaxResult remove(@PathVariable Long[] paramIds)
    {
        return toAjax(reportParamService.deleteReportParamByParamIds(paramIds));
    }
}
